import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;


public class mang2chieu {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		//arraylist
//		exArrayList();
		//
		exSetCollection();
		//
		exMap();
	}

	private static void exArrayList(){
		
		int n = 5;
		//arraylist object
		ArrayList arr = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr.add( new Integer(i));			
		}
		
		for (int i = 0; i < n; i++) {
			System.out.println( arr.get(i) );
		}
		
		ArrayList<String>arrInt = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arrInt.add( "aaaa" + i);			
		}
		
		for (int i = 0; i < n; i++) {
			System.out.println( arrInt.get(i) );
		}
		
		/*Collections.sort(arr, new Comparator<T>() {
		})*/
		
	}
	
	private static void exSetCollection(){
		
		/*
		 * su dung doi tuong TreeSet
		 * - khong uu tien sap theo thu tu
		 * */
		Set<Integer> setHash = new HashSet<>();
		int n = 5;
		//input		
		for (int i = 0; i < n; i++) {
			setHash.add( new Integer(i));			
		}
		for (int i = 0; i < n; i++) {
			setHash.add( new Integer(i));			
		}
		
		//output
		Iterator<Integer> iter = setHash.iterator();
		while (iter.hasNext()) {
			Integer tam = iter.next();
//			System.out.println(tam);
		}
		
		/*
		 * su dung doi tuong TreeSet
		 * - uu tien sap theo thu tu
		 * */
		Set<Integer> treeSet = new TreeSet<>();		
		treeSet.add( new Integer(5));			
		treeSet.add( new Integer(1));
		treeSet.add( new Integer(3));
		treeSet.add( new Integer(2));
		
		//output
		Iterator<Integer> iter1 = treeSet.iterator();
		while (iter1.hasNext()) {
			Integer tam = iter1.next();
			System.out.println(tam);
		}
		
	}
	
	private static void exMap(){
		
		HashMap<Integer, String> map = new HashMap<>();
		/*
		 * de kiem tra mot key co ton tai hay khong
		 * */
		if (map.containsKey(1)==false) {
			map.put(1, "aaaaa");
		}
		
		if (map.containsKey(2)==false) {
			map.put(2, "bbb");
		}
		
		String value = map.get(2);
		System.out.println(value);
		
		Set<Entry<Integer, String>> setIter = map.entrySet();
		Iterator<Entry<Integer, String>> iter = setIter.iterator();
		while (iter.hasNext()) {
			Entry<Integer, String> tam = iter.next();
			System.out.println(tam.getKey());
			System.out.println(tam.getValue());
			
		}
		
	}
	
}
